package com.illya.service.impl;

import com.illya.dao.AccountDao;
import com.illya.exciption.IllyaExciption;
import com.illya.pojo.UserAccount;
import com.illya.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao dao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cost(UserAccount account) {
        try {
            Integer amount = account.getAmount() * 100;
            dao.cost(-amount, account.getCostId());
            dao.cost(amount, account.getSaveId());
        } catch (Exception ex) {
            throw new IllyaExciption("成功开溜~");
        }
    }

}
